﻿//头文件
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include"head.h"

//函数

//加载文件数据函数
void Load(struct student* stu, int* i)
{
	FILE* fp = NULL;
	char s[100];
	fp = fopen("student.txt", "r");
	if (fp == NULL)
	{
		fp = fopen("student.txt", "w+");
		fclose(fp);
		fp = fopen("student.txt", "r");
	}
	fgetc(fp);
	if (feof(fp))
	{
		return;
	}
	else
	{
		fseek(fp, 0, 0);
		do 
		{	
			fseek(fp, 100 * *i, 0);
			fgets(s, 100, fp);
			StrToStru(stu + *i, s);
			(*i)++;
			fseek(fp, 100 * *i + 1, 0);
			fgetc(fp);
		} while (!feof(fp));
	}
	fclose(fp);
}

//录入学生信息函数
void Change(struct student* stu, int* i)
{
	struct student* p;
	char sTemp[20];
	p = stu;
	printf("学号：\n");
	scanf("%s", sTemp);
	p->i_id = atoi(sTemp);
	printf("姓名：\n");
	scanf("%s", p->s_Name);
	printf("性别：\n");
	scanf("%s", p->s_sex);
	printf("作业成绩：\n");
	scanf("%s", sTemp);
	p->f_hwGrade = atof(sTemp);
	printf("考试成绩：\n");
	scanf("%s", sTemp);
	p->f_testGrade = atof(sTemp);
	printf("总评成绩：\n");
	scanf("%s", sTemp);
	p->f_totalGrade = atof(sTemp);
	printf("生源地：\n");
	scanf("%s", p->from);
	(*i)++;
}

//输出写文件函数
void Fout(struct student* stu, int* i)
{
	int j = 0;
	char s[100];
	FILE* fp;
	fp = fopen("student.txt", "w+");
	for (j = 0;j < *i;j++)
	{
		fseek(fp, 100 * j, 0);
		StruToStr(*(stu +j), s);
		fputs(s, fp);
	}
	fseek(fp, 100 * j, 0);
	fputs("#", fp);
	fclose(fp);
}
//显示成绩表函数
void Display(struct student* stu, int* i)
{
	int j = 0;
	system("cls");
	printf("学号\t\t\t姓名\t\t性别\t作业成绩\t考试成绩\t总评成绩\t生源地\n");
	for (j = 0;j < *i;j++)
	{
		printf("%d\t\t%s\t\t%s\t%.1f\t\t%.1f\t\t%.1f\t\t%s\n", (stu + j)->i_id, (stu + j)->s_Name, (stu + j)->s_sex, (stu + j)->f_hwGrade, (stu + j)->f_testGrade, (stu + j)->f_totalGrade, (stu + j)->from);
	}
}
